package de.hawhamburg.androidwecker;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONObject;

import android.util.Log;

public class CommunicationHelper {
	
	private static final String IP = "172.16.0.200";
	private static final String PORT = "12349";
	
	private void statusChanged(Message msg) {
		String[] params = new String[5];
		params[0] = IP; // z.B. 172.16.0.200
		params[1] = PORT; // z.B. 12349
		params[2] = msg.getTopic(); // z.B. LP.LIGHTCONTROL
		params[3] = msg.getTyp(); // Topic oder Queue
		params[4] = msg.getMessage().toString();
		sendMessageToProxy smtp = new sendMessageToProxy();
		smtp.execute(params);
		}

	
    public void setLightColor(int[] intensity, String action) {
    	Map<String,String> valueMap = new HashMap<String, String>();
    	valueMap.put("red",String.valueOf(Math.round(intensity[0]*2.55)));
    	valueMap.put("green",String.valueOf(Math.round(intensity[1]*2.55)));
    	valueMap.put("blue",String.valueOf(Math.round(intensity[2]*2.55)));
    	valueMap.put("fadeTime","0");
    	JSONObject msgValueMap = new JSONObject(valueMap);
    	Map<String,Object> aendernMap = new HashMap<String, Object>();
    	aendernMap.put("values", msgValueMap);
    	aendernMap.put("Id", "client_1578909153");
    	aendernMap.put("Version", null);
    	aendernMap.put("action", action);
    	JSONObject msgFarbeEsszimmerAendern = new JSONObject(aendernMap);
    	Log.d("JSONDemo", msgFarbeEsszimmerAendern.toString());
    	
    	Message msg = new Message();
    	msg.setTopic("LP.LIGHTCONTROL");
    	msg.setTyp("topic");
    	msg.setMessage(msgFarbeEsszimmerAendern.toString());
    	
    	statusChanged(msg);
    }
    
	
    public void setLightStatus(String color, int intensity, String action) {
    	Map<String,String> valueMap = new HashMap<String, String>();
    	valueMap.put(color,String.valueOf(Math.round(intensity*2.55)));
    	valueMap.put("fadeTime","0");
    	JSONObject msgValueMap = new JSONObject(valueMap);
    	Map<String,Object> aendernMap = new HashMap<String, Object>();
    	aendernMap.put("values", msgValueMap);
    	aendernMap.put("Id", "client_1578909153");
    	aendernMap.put("Version", null);
    	aendernMap.put("action", action);
    	JSONArray jsoa = new JSONArray(Arrays.asList(new Integer[]{1,2,3}));
    	aendernMap.put("anAry", jsoa );
    	JSONObject msgFarbeEsszimmerAendern = new JSONObject(aendernMap);
    	Log.d("JSONDemo", msgFarbeEsszimmerAendern.toString());
    	
    	Message msg = new Message();
    	msg.setTopic("LP.LIGHTCONTROL");
    	msg.setTyp("topic");
    	msg.setMessage(msgFarbeEsszimmerAendern.toString());
    	
    	statusChanged(msg);
    }
    
    
}
